#include <cstdio>
#include <algorithm>

using namespace std;

struct Rice
{
    int p, h;
};

bool operator < ( const Rice &a, const Rice &b )
{
    return a.p < b.p;
}

int main( )
{
    int c, m, i;
    double sum, n;
    Rice r[ 1001 ];
    scanf("%d", &c);
    while ( c-- )
    {
        scanf("%lf%d", &n, &m);
        for ( i = 0; i < m; i++ )
            scanf("%d%d", &r[ i ].p, &r[ i ].h);
        sort( r, r + m );
        sum = 0;
        for ( i = 0; i < m; i++ )
        {
            if ( n >= r[ i ].p * r[ i ].h )
            {
                n -= r[ i ].p * r[ i ].h;
                sum += r[ i ].h;
            }
            else
            {
                sum += n / r[ i ].p;
                n = 0;
            }
        }
        printf("%.2lf\n", sum);
    }
    return 0;
}
